{include file="public/head"}

<body>
	<div class="centInput">
		<input type="text" name="true_name" placeholder="请输入姓名" value="{$data.true_name}" />
		<input type="text" name="id_card" placeholder="请输入身份证号"  value="{$data.id_card}" />
		<input type="text" name="phone" placeholder="请输入电话号码"   value="{$data.phone}"/>
		<div class="centInput-code">
			<input type="text" class="centInput-code-left floatLeft" name="code" placeholder="请输入验证码" />
			<input type="button" id="btn" value="获取验证码" class="floatRight" />
		</div>
	</div>
	{:token()}
	<div class="submitCent">
		提交并支付
	</div>
	<script src="__STATIC__/home/js/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>
	<script src="__STATIC__/home/js/swiper.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		$(function () {
			var obj = {};
			window.location.search.slice(1).split('&').forEach(item => {
				var arr = item.split('=');
				obj[arr[0]] = arr[1];
			});
			$('#btn').click(function () {
				var phone = $('input[name="phone"]').val();
				if (!(/^\d{11}$/.test(phone))) {
					alert('请输入正确电话号码');
					return false;
				}
				// 短信
				$.ajax({
					type: 'post',
					url: '/index/Makeupapi/phoneSend',
					data: {
						phone
					},
					success(res) {
						var Time = 60;
						var aa = setInterval(bb, 1000);
						function bb() {
							$("#btn").attr("disabled", true);
							$("#btn").val(Time + "秒后重发");
							if (Time == 0) {
								$("#btn").val("发送验证码").removeAttr("disabled");
								clearInterval(aa);
							}
							Time--;
						}
						if (res.code == 0) {
							alert('发送失败，请重试');
							clearInterval(aa);
						}

					},
                    error() {
                        alert('短信接口错误');
                    }
				});

			});
			// 提交支付
			$('.submitCent').click(function () {
				var true_name = $('input[name="true_name"]').val();
				if (!true_name) {
					alert('请输入姓名');
					return false;
				}
				var id_card = $('input[name="id_card"]').val();
				if (!(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/).test(id_card)) {
					alert('请输入正确身份证');
					return false;
				}
				var phone = $('input[name="phone"]').val();
				if (!(/^\d{11}$/.test(phone))) {
					alert('请输入正确电话号码');
					return false;
				}
				var code = $('input[name="code"]').val();
				if (!code) {
					alert('请输入验证码');
					return false;
				}
				new Promise((resolve) => token(resolve)).then(e => {
					$.ajax({
						type: 'post',
						url: '/index/Makeupapi/markSubmit',
						data: {
							true_name,
							id_card,
							phone,
							d_id: obj.id,
							code,
							__token__: e,
						},
						success(res) {
							if (res.code == 1) {
								window.location.href = res.jump_url;
							} else if (res.code == 1000) {
								alert('您已提交过，请刷新页面重试！');
							} else {
								alert(res.msg);
							}
						}, error() { alert('提交支付接口错误！'); }
					})
				});
			});

			// token令牌
			function token(cb) {
				$.ajax({
					type: 'post',
					url: '/index/Makeupapi/token',
					success(res) {
						if (res.code == 1) {
							// alert(res.__token__);
							cb(res.__token__);
						}
					},
					error() { alert('token令牌接口错误'); }
				})
			};


		});
	</script>
</body>

</html>